/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* removeElements(struct ListNode* head, int val){
  struct ListNode* node=head;
  if(head==NULL) return head;
  while(node->next!=NULL)
   {
     if(node->val==val)
     {
       head=node->next;
       node=head;
     }
     else if(node->next->val==val)
     {
       node->next=node->next->next;
     }
     else node=node->next;
   }
   if(head->val==val)
   {
     head=NULL;
   }
   return head;
}
